package cn.jinjimi.app.entity.AppConfig;

import com.google.gson.annotations.SerializedName;

import cn.jinjimi.app.entity.LinkBean;
import cn.jinjimi.base.preference.PreferenceManager;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.base.util.StringUtils;
import cn.jinjimi.app.bean.SharePrefKeys;

import java.util.ArrayList;
import java.util.List;


/**
 * @author zhenhua
 */
public class HomeEntranceList {
    public List<LinkBean> getEntrances() {
        return entrances;
    }
    @SerializedName("home_entrances")
    private List<LinkBean> entrances;

    public HomeEntranceList(List<LinkBean> entrances) {
        this.entrances = entrances;
    }

    public static List<LinkBean> fetchHomeEntranceList() {
        String data = PreferenceManager.getStringData(SharePrefKeys.PREF_CONFIG_ENTRANCE_LIST);
        if (StringUtils.isNotEmpty(data)) {
            HomeEntranceList list = GsonUtils.fromJson(data, HomeEntranceList.class);
            if (list != null) {
                return list.getEntrances();
            }
        }
        return new ArrayList<>();
    }

    public static void save(List<LinkBean> list) {
        PreferenceManager.setData(SharePrefKeys.PREF_CONFIG_ENTRANCE_LIST, GsonUtils.toJson(new HomeEntranceList(list)));
    }
}
